package com.example.demo.niuke.huawei_b;

import java.util.Scanner;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname Main
 * @description
 * @date 2023/09/02 14:52
 * <p>
 * ******************************************************
 */
public class Main {

    /**
     * 连续递增数字：8 9 10 11 12，生成字符串89101112，随机打乱98111102
     * 找到8
     *
     *
     *
     * @param args
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int n = in.nextInt();
        int i = str.length() / n - 1;
        long start = i == 1 ? 0 : (long) Math.pow(10, i - 1);
        for (; ; start++) {
            StringBuilder sb = new StringBuilder(str);
            if (isVaild(sb, start)) break;
        }
        System.out.println(start);
    }

    private static boolean isVaild(StringBuilder sb, long start) {
        String str = String.valueOf(start);
        int vaild = str.length();
        for (char c : str.toCharArray()) {
            for (int i = 0; i < sb.toString().length(); i++) {
                if (c == sb.charAt(i)) {
                    vaild--;
//                    sb.deleteCharAt(i);
                    sb.delete(i, i+1);
                    break;
                }
            }
        }
        if (vaild != 0) {
            return false;
        } else if (sb.length() != 0) {
            return isVaild(sb, start + 1);
        }
        return true;
    }
}
